package com.weixin.paleituo.base;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;

import com.weixin.paleituo.util.LoadingDialogUtils;

import butterknife.ButterKnife;
import butterknife.Unbinder;
import io.reactivex.subjects.PublishSubject;

/**
 * Author yichao
 * Time  2017/11/27 16:36
 * Dest  Activity的基类
 */

public abstract class BaseActivity extends AppCompatActivity {
    public String TAG=this.getClass().getSimpleName();
    private Unbinder mUnbinder;
    public final PublishSubject<ActivityLifeCycleEvent> lifecycleSubject = PublishSubject.create();
    private Dialog mLoadingDialog;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        lifecycleSubject.onNext(ActivityLifeCycleEvent.CREATE);
        super.onCreate(savedInstanceState);
 /*       if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
        }*/

        ActionBar actionBar = getSupportActionBar();
        actionBar.hide();
        initView();
        mUnbinder = ButterKnife.bind(this);
        initData();
        initEvent();



    }

    /**
     * 展示加载弹框
     *
     * @author fengzhen
     * @version v1.0, 2018/3/29
     */
    protected void showLoadingDialog() {
        if (mLoadingDialog == null) {
            mLoadingDialog = LoadingDialogUtils.createLoadingDialog(this, "");
        }
        if (!mLoadingDialog.isShowing()) {
            mLoadingDialog.show();
        }
    }

    /**
     * 隐藏加载弹框
     *
     * @author fengzhen
     * @version v1.0, 2018/3/29
     */
    protected void dismissLoadingDialog(){
        LoadingDialogUtils.closeDialog(mLoadingDialog);
    }

    /**
     * 初始化事件
     */
    protected  void initEvent(){};
    /**
     * 初始化数据
     */
    protected  void initData(){};

    /**
     * 初始化界面
     */
    protected abstract void initView();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        lifecycleSubject.onNext(ActivityLifeCycleEvent.DESTROY);
        if (mUnbinder!=null){
            mUnbinder.unbind();
        }
    }
    @Override
    protected void onPause() {
        lifecycleSubject.onNext(ActivityLifeCycleEvent.PAUSE);
        super.onPause();
    }

    @Override
    protected void onStop() {
        lifecycleSubject.onNext(ActivityLifeCycleEvent.STOP);

        super.onStop();
    }

    @Override
    protected void onResume() {
        super.onResume();

    }
}
